package request

import (
	"encoding/json"
	"github.com/emicklei/go-restful"
	"net"
)

func GetRequestIP(req *restful.Request) string {

	address, _, err := net.SplitHostPort(req.Request.RemoteAddr)
	if err != nil {
		return req.Request.RemoteAddr
	}

	return address
}

func GetRequestHeader(req *restful.Request) string {
	b, _ := json.Marshal(req.Request.Header)
	return string(b)
}

func GetRequestToken(req *restful.Request) string {
	return req.HeaderParameter("Authorization")
}
